package com.bawei.module_live.version2.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_live.R
import com.bawei.module_live.version2.mvi.model.entity.ImEntity

class ImAdapter() : RecyclerView.Adapter<ImAdapter.ImViewHolder>() {
//    private val data: ArrayList<ImEntity>=[]
private val data = arrayListOf<ImEntity>()
    // 添加数据更新方法
    fun updateData(newList: List<ImEntity>) {
        data.clear()
        data.addAll(newList)
        notifyDataSetChanged()
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_im, parent, false)
        return ImViewHolder(view)
    }
    override fun onBindViewHolder(holder: ImViewHolder, position: Int) {
        holder.tv1.text = "${data[position].name}:"
        holder.tv2.text = data[position].content
    }
    override fun getItemCount() = data.size
    class ImViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val tv1: TextView = itemView.findViewById(R.id.tv1)
        val tv2: TextView = itemView.findViewById(R.id.tv2)
    }
}